import com.itheima.ui.GameJFrame;
import com.itheima.ui.LoginJFrame;
import com.itheima.ui.RegisterJFrame;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.MalformedURLException;
import java.net.URL;
import java.net.URLConnection;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.Objects;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class App {
    public static void main(String[] args) throws RuntimeException {
        // 表示程序的启动入口
        // new GameJFrame();
        Runtime r = Runtime.getRuntime();
//        System.out.println(Objects.isNull(null));
//        System.out.println(r.availableProcessors());
//        System.out.println(r.maxMemory() / 1024 / 1024);
//        System.out.println(r.totalMemory() / 1024 / 1024);
        String reg1 = "1[3-9]\\d{9}";
        String reg2 = "1[3-9]\\d{10}";
        String reg3 = "[1-9]\\d{16}(\\d|(?i)x)";
        String str = "44162219891106163X";
//        System.out.println(str.matches(reg3));
        int[] arr = { 6, 1, 2, 7, 9, 3, 4, 5, 10, 8 };
//        int[] arr = { 6, 1, 2, 5, 9, 3, 4, 7, 10, 8 };

        quickSort(arr, 0, arr.length-1);
        for (int i = 0; i < arr.length; i++) {
            System.out.print(arr[i] + " ");
        }
    }
    public static void quickSort(int[] arr, int i, int j){
        int start = i;
        int end = j;
        int baseNumber = arr[i];

        while( start != end ){
            //利用end从后往前开始找，找比基准数小的数字
            while(true){
                if ( end <= start || arr[end] < baseNumber ) {
                    break;
                }
                end--;
            }
            //利用start从前往后找，找比基准数大的数字
            while(true){
                if ( end <= start || arr[start] > baseNumber ) {
                    break;
                }
                start++;
            }
            //把start和end指向的元素进行交换
            System.out.printf("start:%d end:%d%n", start, end);
            int temp = arr[start];
            arr[start] = arr[end];
            arr[end] = temp;
        }
        //当start和end指向同一个元素的时候，上面循环结束
        int temp = arr[i];
        arr[i] = arr[start];
        arr[start] = temp;
    }
    private static void formatDate() {
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy年MM月dd日 HH:mm");
        System.out.println(sdf);
        Date d3 = new Date(0L);
        String str3 = sdf.format(d3);
        System.out.println(d3);
        System.out.println(str3);
    }
    private static void grabSomeData() {
        URL url = null;
        try {
            url = new URL("https://baidu.com");
        } catch (MalformedURLException e) {
            throw new RuntimeException(e);
        }
        URLConnection conn = null;
        try {
            conn = url.openConnection();
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
        //创建一个对象去读取网络接口中的数据
        try {
            BufferedReader br = new BufferedReader(new InputStreamReader(conn.getInputStream()));
            String line;
//            String regex = "[1-9]\\d{17}";
            String regex = "登录";
            Pattern pattern = Pattern.compile(regex);
            while((line = br.readLine()) != null ) {
                System.out.println(line);
                Matcher matcher = pattern.matcher(line);
                while(matcher.find()){
                    System.out.println(matcher.group());
                }
            }
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
    }
}
